<?php
error_reporting(0);
session_start();
include_once '../comm/config.php';
include_once '../comm/Taoapi.php';
include_once '../comm/page.class.php';
include_once '../comm/checkpostandget.php';

$sort=empty($_GET['sr']) ? 'commissionVolume_desc' : $_GET['sr']; 
$iid=$_GET['id']; 
$userid=$_GET['u']; 
$qkey=urldecode($_GET['qkey']);
$page = !($_GET['page'])?'1':intval($_GET['page']);
$pagesize=20;

$sql="select * from ".$BIAOTOU."user where Id ='".$userid."'";
$rs = mysql_query($sql);
while ($row = mysql_fetch_array($rs)){
	$username=$row['ddusername'];
	$dengji=$row['dengji'];
}
mysql_close($dblink);

$Taoapi_Config = Taoapi_Config::Init();
$Taoapi_Config->setCharset('UTF-8');
$Taoapi = new Taoapi;
//获取该页面的商品信息
$Taoapi->method = 'taobao.taobaoke.items.detail.get';
$Taoapi->fields = 'num_iid,title,nick,pic_url,price,click_url,shop_click_url,commission,commission_rate,commission_num,commission_volume';
$Taoapi->nick = MYUSERNICK;
$Taoapi->num_iids=$iid;
$Taoapi->outer_code=$userid;
$MyTaoItem = $Taoapi->Send('get','xml')->getArrayData();
$Mytotal=$MyTaoItem['total_results'];
$MyItem=$MyTaoItem['taobaoke_item_details']['taobaoke_item_detail'];

$commParam['method'] = 'taobao.taobaoke.items.convert';
$commParam['fields'] = 'commission,shop_click_url,click_url';
$commParam['nick'] =  MYUSERNICK;
$commParam['outer_code'] = $userid;
$commParam['num_iids']=$iid;
$Taoapi->setUserParam($commParam);//传入参数
$CommData = $Taoapi->Send('get','xml')->getArrayData();
$ThisComm1=$CommData['taobaoke_items']['taobaoke_item'];
$ThisComm=$CommData['taobaoke_items']['taobaoke_item']['commission'];

//获取同名商品
$TaobaokeParam['method'] = 'taobao.taobaoke.items.get';
$TaobaokeParam['fields'] = 'iid,num_iid,title,nick,type,pic_url,price,click_url,shop_click_url,commission,commission_rate,commission_num,commission_volume';
$TaobaokeParam['nick'] = MYUSERNICK;
$TaobaokeParam['outer_code'] = $userid;
$TaobaokeParam['page_size'] =$pagesize;
$TaobaokeParam['page_no']= $page;
$TaobaokeParam['keyword'] = $qkey;
$Taoapi->setUserParam($TaobaokeParam);//传入参数
$TaobaokeData = $Taoapi->Send('get','xml')->getArrayData();
$TaobaokeItem1 = $TaobaokeData['taobaoke_items']['taobaoke_item']; 
$TotalResults = $TaobaokeData['total_results']; 

if($TotalResults==1){ 
	$TaobaokeItem[0]=$TaobaokeItem1;
}
else{
	$TaobaokeItem=$TaobaokeItem1;
}

if($TotalResults>$pagesize*100){
	$totalnum=$pagesize*100;
}
else{
	$totalnum=$TotalResults;
}

$strnicks = "";
for($i = 0; $i < count($TaobaokeItem,0); $i++){
	if($i == 0){
		$strnicks = $TaobaokeItem[$i]['nick']; 
	}
	else{
		$strnicks = $strnicks . "," . $TaobaokeItem[$i]['nick']; 
	}
}

$Taoapi->method = 'taobao.users.get';
$Taoapi->fields = 'nick,seller_credit,location';
$Taoapi->nicks = $strnicks;
$TaoapiUsers = $Taoapi->Send('get','xml')->getArrayData();
$Result_users1 = $TaoapiUsers["users"]["user"]; 
if($TotalResults==1){ 
	$Result_users[0]=$Result_users1;
}
else{
	$Result_users=$Result_users1;
}
?><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3c.org/TR/1999/REC-html401-19991224/loose.dtd">
<HTML xmlns="http://www.w3.org/1999/xhtml">
<HEAD>
<META content="text/html; charset=utf-8" http-equiv=Content-Type>
<TITLE>返现宝搜索结果 - 淘宝网购物返现</TITLE>
<LINK rel=stylesheet type=text/css href="css/apisearch.css">
<META name=GENERATOR content="MSHTML 8.00.6001.18975"></HEAD>
<BODY topMargin=0>

<div class="right_pro" id="fanlibao" style="width:685px; margin:auto;">
<!--顶部-->
    <h4><span style="float:right; padding-right:10px;"><?php if($username!=''){?>你所绑定的<?=WEBNICK?>账号<strong><?=$username?></strong><?php }else{ ?>尚未<?=WEBNICK?>注册，请先<a href="http://<?=URL?>/user/register.php" target="blank">注册绑定</a>！否则无法自动返现！<?php } ?></span><strong>当前掌柜商品：</strong> (掌柜：<a href="<?=$MyItem['click_url']?>" target="_top"><font><?=$MyItem['item']['nick']?></font></a>)</h4>
    <!--第一件商品开始-->
<?php if($Mytotal==1){?>
<div class="right_sk"\>
	<h6><a href="<?=$MyItem['click_url']?>" target="_top"><?=$qkey?></a>
	</h6>
	<div class="pic"><a href="<?=$MyItem['click_url']?>" target="_top"><img src="<?=$MyItem['item']['pic_url']?>" /></a>
	</div>
	<div class="icon_fan">
	</div>
	<div class="right_price">淘宝价：<span><?=$MyItem['item']['price']?></span>元<br />返现金：<span><?php echo ck_fxje($ThisComm,$dengji);?></span>元
	</div>
	<div class="sk_submit"><a  target="_top" href="<?=$ThisComm1['click_url']?>">购物拿返现</a>
	</div>
</div>
<?php }else{?>
<!--第一件end-->
<!--如果没有推广商品显示页面-->
<div class="right_sk"\>
    <div class="right_no">
    对不起，此宝贝没有参加淘宝返现计划！<br><br>
    请查看该商品在其它商家的返现情况
    </div>
</div>
<?php }?>
<!--中间通长-->
<div class="othergood">
<!--其他相同商品-->
<div class="other_left"><strong>其它相同商品：</strong>还找到 <font><strong><?=$TotalResults?></strong></font> 件其它商家有返现的相同商品</div>
<!--END-->
<!--搜索开始-->
<!--搜索结束-->
<div style="clear:both"></div><!--清楚2边-->
</div>
<!--中间通长END-->
<p></p>
<!--列表1开始-->
<div style="width:680px; overflow:hidden;">

<?php	

for($i = 0; $i < count($TaobaokeItem); $i++) {
    echo "<ul>";
	echo "<li class=\"pic\"><a href=\"".$TaobaokeItem[$i]["click_url"]."\" target=\"_blank\"><img src=".$TaobaokeItem[$i]['pic_url']."_100x100.jpg width=100 height=100 /></a></li>";
	echo "<li class=\"contain\">";
	echo "<h6><a href=\"".$TaobaokeItem[$i]["click_url"]."\" target=\"_blank\">".$TaobaokeItem[$i]['title']."</a></h6>";
	echo "<div class=\"sx\">掌柜：<a href=\"".$TaobaokeItem[$i]["shop_click_url"]."\" target=\"_blank\">".$TaobaokeItem[$i]["nick"]."</a> <a target=\"_blank\" href=\"http://amos1.taobao.com/msg.ww?v=2&uid=".$TaobaokeItem[$i]["nick"]."&s=2\" ><img border=\"0\" src=\"http://amos1.taobao.com/online.ww?v=2&uid=".$TaobaokeItem[$i]["nick"]."&s=2\" align=\"middle\" /></a></div>";
	echo "<div class=\"sx\">　 区域：".$Result_users[$i]['location']['city']."</div><div class=\"sx\">淘宝价：<span>".$TaobaokeItem[$i]['price']."</span> 元</div>";
	echo "<div  class=\"clear\"></div>";
 	echo "<div class=\"sx\">信誉：";
	if($Result_users[$i]['type']=="B")
	{
		echo " <img src=\"images/shangcheng.png\" alt=\"商城卖家\">";
	}else{
		echo " <img src=\"images/level_".$Result_users[$i]["seller_credit"]["level"].".gif\" align=\"absmiddle\" />";
	}
 	echo "</div>";
 	echo "<div class=\"sx\">30天售：".$TaobaokeItem[$i]["commission_num"]." 件</div>";
 	echo "<div class=\"sx\">返现金：<span>".ck_fxje($TaobaokeItem[$i]["commission"],$dengji)."</span> 元</div>";
 	echo "</li>";
 	echo "<li class=\"shop\"><a href=".$TaobaokeItem[$i]["click_url"]." target=\"_blank\">购物拿返现</a></li>";
	echo "</ul>";
}

?>
</div>
<!--列表1结束-->
<!--翻页开始-->
<div class="badoo"><?php 
pageft($TotalResults,$pagesize,1,0,1,10,"fanxianbao.php?u=".$userid."&id=".$iid."&qkey=".urlencode($qkey));
echo $pagenav;?></div>
<!--翻页结束-->
</div>
 </BODY></HTML>